package com.ydgk.Test;

import com.ydgk.bean.Commodity;
import com.ydgk.dao.CommDao;
import com.ydgk.dao.RecordDao;
import org.junit.Before;
import org.junit.Test;

import java.util.List;

public class CommodityDaoTest {
    protected CommDao commDao;
    @Before
    public void init(){commDao=new CommDao(); }

    @Test
    public void deleteById(){
         System.out.println(commDao.deleteById(5));
    }

    @Test
    public void findAllTest(){
        List<Commodity> all = commDao.findAll();
        for (Commodity commodity : all) {
            System.out.println(commodity);
        }
    }
    @Test
    public void updateById(){
        Commodity commodity = new Commodity();
        commodity.setCid(1);
        commodity.setCprice(2);
        commodity.setCprovider(1);
        System.out.println(commDao.updateById(commodity));;
    }

    @Test
    public void saveTest(){
        Commodity commodity=new Commodity();
        commodity.setCname("百世可乐");
        commodity.setCface("image/3.jpg");
        commodity.setCprice(3);
        commodity.setCprovider(1);
        commodity.setCtype(1);
        commodity.setCnum(5);
        System.out.println(commDao.save(commodity));
    }

    @Test
    public void updateCnumById(){
        System.out.println(commDao.updateCnum(1,1));
    }

    @Test
    public void insertTest(){
        RecordDao recordDao = new RecordDao();
        int i=recordDao.insert(1,"delete");
        System.out.println(i);
    }
}
